package com.app.util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.sql.Connection;
import java.sql.DriverManager;

public class JDBC {
//	private static String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
//	private static String user="sa";
//	private static String pwd="shich";
	private Properties ps= getProperties();
	
	private  Properties getProperties(){
		Properties ps= new Properties();
		try{
			InputStream in=getClass().getResourceAsStream("../../../jdbc.properties");
			ps.load(in);
		}catch(Exception e){
			
		}
		return ps;
	}
	public Connection getConnection(){
		Connection conn=null;
		try{
			//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			System.out.println(ps.getProperty("driverClass"));
			Class.forName(ps.getProperty("driverClass"));
			conn=DriverManager.getConnection(ps.getProperty("jdbcUrl"), ps.getProperty("user"), ps.getProperty("password"));
		}catch(Exception e){
			e.printStackTrace();
		}
		return conn;
	}
	public void close(ResultSet rs,PreparedStatement ps,Connection conn){
		try{
			if(rs!=null){
				rs.close();
			}
			if(ps!=null){
				ps.close();
			}
			if(conn!=null){
				conn.close();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		JDBC db=new JDBC();
		System.out.println(db.getConnection());
	}
}

